package net.zjitc.service.impl;

import net.zjitc.mapper.SaleMapper;
import net.zjitc.pojo.Sale;
import net.zjitc.service.SaleService;
import net.zjitc.vo.DateVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.List;

/**
 * @Author admin
 * @DATE 2019/4/10 11:22
 */
@Service
@Transactional
public class SaleServiceImpl implements SaleService {
    @Autowired
    SaleMapper saleMapper;

    @Override
    public List<Sale> findSaleInfo(DateVo vo) {
        /*如果年为空，则默认为当年*/
        if (StringUtils.isBlank(vo.getYear())){
            Calendar date = Calendar.getInstance();
            vo.setYear(String.valueOf(date.get(Calendar.YEAR)));
        }
        if ("0".equals(vo.getMonth())){
            vo.setMonth(null);
        }
        return saleMapper.salesRank(vo);
    }

    @Override
    public String deleteOrderById(Integer id) {

        deleteOrderById(id);
        return "/admin/orders/list.jsp";
    }
}
